<div class="CommonHeader">
  <div class="CommonBackBtn">
    <a href="javascript:history.go(-1)"
      ><img src="__CDN__/map/images/return_black.png" alt="返回"
    /></a>
  </div>
  <div class="CommonTitle">提现</div>
  <div class="CommonDetail">
    <a href="{:url('user/accountdetail')}"
      ><img src="__CDN__/map/images/The_detail.png" alt=""
    /></a>
  </div>
</div>

<div class="CommonMain">
  <div class="DrawingstTop">
    <p class="p1">提款金额</p>
    <div class="p2 customer">
      <span class="w_10">￥</span
      ><input class="customer" type="number" name="money" value="" />
    </div>
    <p class="p3"> <span id="could_withdraw"></span></p>
    <p class="p4 customer">
      最低提现金额不能低于{$cash_min}元的
    </p>
    <p class="p5" id="withdrawAll">全部提现</p>
  </div>

  <!--<div class="DrawingstTitle">提现账户选择</div>-->
  <div class="DrawingstList">
    {foreach $bank as $vo}
    <div class="DrawingstCli am-cf">
      <div class="am-fl intre">
        <input id="item1" type="radio" name="item" {if condition="$vo['status']
        eq 1"}checked='checked'{/if} value="{$vo.id}">
        <label for="item1"></label>
      </div>
      <div class="am-fl bankName">
        <p class="p1">{$vo.name}</p>
        <p class="p2">储蓄卡</p>
      </div>
      <div class="am-fr bankNumber">
        <p class="pp1">{$vo.account}</p>
        <p></p>
      </div>
    </div>
    {/foreach}
  </div>

  <div class="DrawingstTitle">提现账户管理</div>
  <div class="DrawingstLink ">
    <a href="{:url('user/bankaccount')}" class="am-cf">
      提现账户管理
      <p class="img am-fr"><img src="__CDN__/map/images/arrow_right.png" /></p>
    </a>
  </div>

  <div class="DmBtn Mt60">
    <input disabled class="u-high" type="button" value="立即申请" />
  </div>
</div>
<style>
  .u-high{background-color: gray !important;}
  .DrawingstTop div:nth-child(2) {
    display: flex;
  }
  .DrawingstTop div:nth-child(2) input {
    font-size: 0.32rem !important;
    height: 100% !important;
  }
  .bankNumber .pp1 {
    font-size: 0.32rem;
    line-height: 0.4rem;
    color: #333;
  }
</style>

<script>
  var is_post=0;
  var http_url = "{$http_url}"
  //提现全部按钮
  $(document).on('click','#item1',function(){
    
    // if($(this).val() && $(this).val() > 2){
    //    if($(this).val() == Number($(this).val()).toFixed(2)) {
    //      $(".u-high").addClass('gradualBg').attr("disabled",false);
    //    }      
    // }
  })
  
  $("#withdrawAll").on("click", function() {
    var chould_withdraw = Number($("#could_withdraw").html())
    $("input[name='money']").val(chould_withdraw)
      $(".u-high").addClass("gradualBg").attr("disabled",false)
  })
  $("input[name=money]").on("input", function() {     
    var reg = new RegExp(/^(\d+|\d+\.\d{1,2})$/)
    var exp = new RegExp(/^\d*.?\d*$/)
    console.log(reg.test($(this).val()))
    if(exp.test($(this).val()) == false){
      $(".u-high").removeClass("gradualBg").attr("disabled",true)
      return $(this).val('')
    }
    
      if($(this).val().indexOf('.') !== -1 && $(this).val() > 2){
        // $(this).val(parseFloat(Number($(this).val()).toFixed(2)));
        // let pointPosition = $(this).val().indexOf('.') + 1;
        //   // 查询小数点后方字符串长度 不允许大于2
        //   if ($(this).val().substring(pointPosition).length > 1) {
        //     return false;
        //   }
        $(this).val($(this).val().substr(0,$(this).val().indexOf(".")+3))
        $(".u-high").addClass("gradualBg").attr("disabled",false)
      }else if($(this).val() > 2){
        $(".u-high").addClass("gradualBg").attr("disabled",false)
      }else {
        $(".u-high").removeClass("gradualBg").attr("disabled",true)
      }
    
    // var numindex = parseInt(getVal.indexOf("."),10); 
    //         var head = getVal.substring(0,numindex);
    //         var bottom = getVal.substring(numindex,numindex+3);
    //         var fianlNum = head+bottom;
            // $(this).val(fianlNum);
      // console.log(parseFloat(Number(getVal).toFixed(2)))
      // 1.先把输入框里面的值拿出来
      // 2.对已输入的值进行检测，如果多小数后超过2位 return false
      
    //   $(this).val(parseFloat(Number($(this).val()).toFixed(2)));
    // if ($(this).val() > 2 && reg.test($(this).val())) {               
    //   $(".u-high").addClass("gradualBg").attr("disabled",false)
    // } else {
    //   $(".u-high").removeClass("gradualBg").attr("disabled",true)
    // }
  })
  //提现
  $(".u-high").on("click", function() {
      if(is_post==1){
          alert('提现正在进行中,请稍等')
      }
      is_post=1;
    var item = $("input[type='radio']:checked").val()
    var money = $("input[name='money']").val()
    $.ajax({
      type: "POST",
      url: "{$http_url}/index/user/tempted",
      dataType: "json",
      data: {
        item: item,
        money: money
      },
      success: function(data) {
          is_post=0;
        alert(data.msg)
        if (data.code > 0) {
          history.go(-1)
        } else {
          $("input[name='__token__']").val(data.token)
        }
      },
      error: function(jqXHR) {
        console.log("Error: " + jqXHR.status)
      }
    })
  })
</script>
